package model

import (
	"gorm.io/gorm"
	"time"
)

type TopicNode struct {
	Nid      string    `json:"nid"`
	Name     string    `json:"name" binding:"required" form:"name"`
	CreateAt time.Time `json:"create_at"`
}

func (t TopicNode) TableName() string {
	return "topic_node"
}

func (t *TopicNode) BeforeCreate(tx *gorm.DB) error {
	t.CreateAt = time.Now()
	return nil
}

//Topic 帖子表
type Topic struct {
	Tid      string    `json:"tid"`
	Nid      string    `json:"nid" binding:"required" form:"nid"`
	Uid      string    `json:"uid"`
	Title    string    `json:"title" binding:"required" form:"title"`
	Content  string    `json:"content" binding:"required" form:"content"`
	CreateAt time.Time `json:"create_at"`
	UpdateAt time.Time `json:"update_at"`
	Deleted  int       `json:"deleted"`

	CreateBy string `json:"create_by" gorm:"<-:false"`
}

func (t Topic) TableName() string {
	return "topic"
}

func (t *Topic) BeforeCreate(tx *gorm.DB) error {
	t.CreateAt = time.Now()
	t.UpdateAt = time.Now()
	return nil
}

func (t *Topic) BeforeUpdate(tx *gorm.DB) error {
	t.UpdateAt = time.Now()
	return nil
}
